home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / disk / Disk.man < prev    next >
Encoding:
Text File  |  1992-08-31  |  15.1 KB  |  362 lines

  1. '\" Copyright 1989 Regents of the University of California
  2. '\" Permission to use, copy, modify, and distribute this
  3. '\" documentation for any purpose and without fee is hereby
  4. '\" granted, provided that this notice appears in all copies.
  5. '\" The University of California makes no representations about
  6. '\" the suitability of this material for any purpose.  It is
  7. '\" provided "as is" without express or implied warranty.
  8. '\" 
  9. '\" $Header: /sprite/src/lib/disk/RCS/Disk.man,v 1.8 92/08/31 12:20:45 voelker Exp $ SPRITE (Berkeley)
  10. '/" 
  11. .so \*(]ltmac.sprite
  12. .HS Disk lib
  13. .BS
  14. .SH NAME
  15. .VS
  16. Disk_ReadLabel, Disk_WriteLabel, Disk_EraseLabel, Disk_NewLabel, Disk_ReadDecLabel, Disk_WriteDecLabel, Disk_ReadSunLabel,  Disk_WriteSunLabel, Disk_HasFilesystem, Disk_ReadLfsSuperBlock, Disk_WriteLfsSuperBlock, Disk_ReadLfsCheckpointHdr, Disk_WriteLfsCheckPointHdr, Disk_WriteLfsCheckPointArea, Disk_LfsCheckpointTrailer, Disk_ForEachCheckpointRegion, Disk_ReadDomainHeader, Disk_WriteDomainHeader, Disk_ReadSummaryInfo, Disk_WriteSummaryInfo, Disk_SectorRead, Disk_SectorWrite, Disk_BlockRead, Disk_BlockWrite, Disk_BadBlockRead, Disk_FragRead, Disk_FragWrite, Disk_PrintDomainHeader, Disk_PrintSummaryInfo, Disk_PrintFileDescBitmap, Disk_PrintDataBlockBitmap, Disk_PrintDirEntry, Disk_PrintLabel, Disk_PrintLfsSuperBlock, Disk_PrintLfsSuperBlockHdr, Disk_PrintLfsDescMapParams, Disk_PrintLfsSegUsageParams, Disk_PrintLfsFileLayoutParams, Disk_PrintLfsStableMemParams, Disk_PrintLfsCheckpointHdr, Disk_PrintLfsCheckpointRegion, Disk_PrintLfsCheckpointTrailer 
  17. \- Package for accessing OFS and LFS file systems via raw disks
  18. .VE
  19. .SH SYNOPSIS
  20. .nf
  21. .VS
  22. #include <disk.h>
  23. .VE
  24. .VS
  25. Disk_Label *
  26. \fBDisk_ReadLabel\fR(\fIfileID\fR)
  27. int
  28. \fBDisk_WriteLabel\fR(\fIfileID, labelPtr\fR)
  29. Disk_Label *
  30. \fBDisk_NewLabel\fR(\fIlabelType\fR)
  31. int
  32. \fBDisk_EraseLabel\fR(\fIfileID, labelType\fR)
  33. .VE
  34. .VS
  35. Dec_DiskLabel *
  36. \fBDisk_ReadDecLabel\fR(\fIfileID\fR)
  37. int
  38. \fBDisk_WriteDecLabel\fR(\fIfileID, decLabelPtr\fR)
  39. .VE
  40. Sun_DiskLabel *
  41. \fBDisk_ReadSunLabel\fR(\fIfileID\fR)
  42. .VS
  43. int
  44. \fBDisk_WriteSunLabel\fR(\fIfileID, sunLabelPtr\fR)
  45. .VE
  46. .VS
  47. Ofs_DomainHeader *
  48. \fBDisk_ReadDomainHeader\fR(\fIfileID, labelPtr\fR)
  49. int
  50. \fBDisk_WriteDomainHeader\fR(\fIfileID, labelPtr, headerPtr\fR)
  51. .VS
  52. Ofs_SummaryInfo *
  53. \fBDisk_ReadSummaryInfo\fR(\fIfileID, labelPtr\fR)
  54. int
  55. \fBDisk_WriteSummaryInfo\fR(\fIfileID, labelPtr, summaryPtr\fR)
  56. .VE
  57. .VE
  58. int
  59. \fBDisk_SectorRead\fR(\fIfileID, index, count, buffer\fR)
  60. int
  61. \fBDisk_SectorWrite\fR(\fIfileID, index, count, buffer\fR)
  62. int
  63. \fBDisk_BlockRead\fR(\fIfileID, headerPtr, index, count, buffer\fR)
  64. int
  65. \fBDisk_BlockWrite\fR(\fIfileID, headerPtr, index, count, buffer\fR)
  66. int
  67. \fBDisk_BadBlockRead\fR(\fIfileID, headerPtr, index, buffer\fR)
  68. int
  69. \fBDisk_FragRead\fR(\fIfileID, headerPtr, index, count, buffer\fR)
  70. int
  71. \fBDisk_FragWrite\fR(\fIfileID, headerPtr, index, count, buffer\fR)
  72. void
  73. \fBDisk_PrintDomainHeader\fR(\fIheaderPtr\fR)
  74. void
  75. \fBDisk_PrintSummaryInfo\fR(\fIsummaryPtr\fR)
  76. .VS
  77. \fBDisk_PrintLabel\fR(\fIlabelPtr\fR)
  78. .VE
  79. void
  80. \fBDisk_PrintFileDescBitmap\fR(\fIheaderPtr, bitmap\fR)
  81. void
  82. \fBDisk_PrintDataBlockBitmap\fR(\fIheaderPtr, bitmap\fR)
  83. void
  84. \fBDisk_PrintDirEntry\fR(\fIdirEntryPtr\fR)
  85. .VS
  86. int
  87. \fBDisk_HasFilesystem\fR(\fIfileID, labelptr\fR)
  88. LfsSuperBlock*
  89. \fBDisk_ReadLfsSuperBlock\fR(\fIfileId, labelPtr\fR)
  90. ReturnStatus
  91. \fBDisk_WriteLfsSuperBlock\fR(\fIfileId, lfsSuperPtr\fR)
  92. LfsCheckPointHdr*
  93. \fBDisk_ReadLfsCheckPointHdr\fR(\fIfileId, labelPtr, areaPtr\fR)
  94. ReturnStatus
  95. \fBDisk_WriteLfsCheckPointHdr\fR(\fIfileId, headerPtr, area, labelPtr\fR)
  96. ReturnStatus
  97. \fBDisk_WriteLfsCheckPointArea\fR(\fIfileId, headerPtr, area, labelPtr\fR)
  98. LfsCheckPointTrailer*
  99. \fBDisk_LfsCheckPointTrailer\fR(\fIcheckPointHdrPtr\fR)
  100. ReturnStatus
  101. \fBDisk_ForEachCheckPointRegion\fR(\fIcheckPointHdrPtr, regionProc\fR)
  102. void
  103. \fBDisk_PrintLfsSuperBlockHdr\fR(\fIlfsSuperHdrPtr\fR)
  104. void
  105. \fBDisk_PrintLfsStableMemParams\fR(\fIstableMemPtr\fR)
  106. void
  107. \fBDisk_PrintLfsDescMapParams\fR(\fIdescMapPtr\fR)
  108. void
  109. \fBDisk_PrintLfsSegUsageParams\fR(\fIsegUsagePtr\fR)
  110. void
  111. \fBDisk_PrintLfsFileLayoutParams\fR(\fIfileLayoutPtr\fR)
  112. void
  113. \fBDisk_PrintLfsSuperBlock\fR(\fIlfsSuperPtr\fR)
  114. void
  115. \fBDisk_PrintLfsCheckPointHdr\fR(\fIcheckPointHdr\fR)
  116. void
  117. \fBDisk_PrintLfsCheckPointRegion\fR(\fIregionPtr\fR)
  118. void
  119. \fBDisk_PrintLfsCheckPointTrailer\fR(\fItrailerPtr\fR)
  120. .VE
  121. .SH ARGUMENTS
  122. .AS Ofs_DomainHeader blockNumber
  123. .AP int fileID in
  124. File descriptor from \fBopen\fP of raw disk.
  125. .AP int partition in
  126. Index of partition to access, 0-7.
  127. .VS
  128. .AP Disk_Label *labelPtr in
  129. Basic disk information from \fBDisk_ReadLabel\fP.
  130. .AP Disk_NativeLabelType labelType in
  131. Type of machine-specific (native) disk label on the disk.
  132. .AP Dec_DiskLabel *decLabelPtr
  133. Native disk label for ds3100s.
  134. .AP Sun_DiskLabel *sunLabelPtr
  135. Native disk label for Suns.
  136. .VE
  137. .AP int index in
  138. Index of first (sector/block/fragment) to transfer.
  139. .AP int count in
  140. Number of (sectors/blocks/fragments) to transfer.
  141. .AP char *buffer in
  142. Buffer for data transferred.
  143. .AP Ofs_DomainHeader *headerPtr in
  144. Disk header information from \fBDisk_ReadDiskHeader\fP.
  145. .AP Ofs_SummaryInfo *summaryPtr in
  146. Disk summary information sector.
  147. .AP char *bitmap in
  148. Array of bitmap bytes.
  149. .AP Fslcl_DirEntry *dirEntryPtr in
  150. Directory entry structure.
  151. .AP LfsSuperBlock *lfsSuperPtr in
  152. LFS Super Block structure.
  153. .AP LfsSuperBlockHdr *lfsSuperHdrPtr in
  154. Static parameters describing LFS layout on disk.
  155. .AP LfsCheckPointHdr *checkPointHdrPtr in
  156. Structure describing and heading a LFS checkpoint area.
  157. .AP int areaPtr out
  158. If non-NULL, returns the checkpoint the header is for.
  159. .AP int area in
  160. Flag determining the checkpoint area (0 or 1).
  161. .AP LfsCheckPointTrailer *trailerPtr in
  162. Structure capping a LFS checkpoinit area.
  163. .AP int\ proc(LfsCheckPointRegion*) regionProc in
  164. Procedure used to iterate over the various checkpoint regions
  165. between the lfsCheckPointHdr and the lfsChecpointTrailer.
  166. .AP LfsStableMemParams *stableMemPtr in
  167. Configuration parameters for stable memory data structures.
  168. .AP LfsDescMapParams *descMapPtr in
  169. LFS descriptor map layout on disk.
  170. .AP LfsSegUsageParams *segUsagePtr in
  171. LFS segment usage array layout description on disk.
  172. .AP LfsFileLayoutParams *fileLayoutPtr in
  173. Number of file descriptors to pack together per block.
  174. .BE
  175.  
  176. .SH INTRODUCTION
  177. .PP
  178. The \fBDisk\fP package is used to read and write raw disks that
  179. are formatted to contain Sprite file systems.  To use these routines correctly
  180. it is important to understand disk \fIpartitions\fP,
  181. file system \fIheader information\fP,
  182. file system \fIblocks\fP, and file system block \fIfragments\fP.
  183. .PP
  184. Each physical disk is divided into as many as 8 partitions.
  185. The letters 'a' through 'h' are used to distinguish these different
  186. partitions in the names of the special device files that are
  187. used to access them.  Thus ``/dev/rsd0a'' references the first (zero'th)
  188. partition on disk \fBrsd0\fP.  
  189. .VS
  190. The partitioning information is stored on the disk in the 
  191. ``disk label''.
  192. This label is in a machine-dependent format, and is referred to as
  193. the ``native disk label''.
  194. Native disk labels are kept in a machine-dependent
  195. location on the disk. 
  196. This is usually in sector 0 or some other sector near
  197. the start of the first partition.
  198. The
  199. \fBfsmake\fP program also
  200. copies the label to a partition when it formats
  201. it into a file system.  
  202. The routines \fBDisk_ReadSunLabel\fP and \fBDisk_ReadDecLabel\fP
  203. can be used to read the native disk labels.
  204. .PP
  205. It is not always convenient to deal with native disk labels.
  206. For this reason a generic label type and associated routines have been
  207. provided.
  208. The type \fBDisk_Label\fR is a standard format for disk labels.
  209. The routine \fBDisk_ReadLabel\fR is used to read a native disk label
  210. off the disk and convert it into a \fBDisk_Label\fR.
  211. The routine \fBDisk_WriteLabel\fR will convert a \fBDisk_Label\fR
  212. into a native disk label and write it on the disk.
  213. Two more procedures are provided for manipulating disk labels.
  214. \fBDisk_EraseLabel\fR will erase a native disk label from the disk,
  215. and \fBDisk_NewLabel\fR is used to create a new label if the disk does not
  216. have one already.
  217. The contents of a \fBDisk_Label\fR are defined in <disk.h>.
  218. .VE
  219. .PP
  220. \fBDisk_HasFilesystem\fR returns the type of file system on the
  221. disk.  If the disk has a LFS file system, DISK_HAS_LFS is returned;
  222. if the disk has an OFS file system, DISK_HAS_OFS is returned;
  223. otherwise, DISK_HAS_NO_FS is returned.
  224. .PP
  225. The detailed structure of the old sprite file system is defined by a
  226. Ofs_DomainHeader structure that is located on the disk according to the
  227. \fBDisk_Label\fP.  This can be obtained with the
  228. \fBDisk_ReadDomainHeader\fP procedure.  The Ofs_DomainHeader structure
  229. is defined in <kernel/fsdm.h>, and is passed to the block and fragment
  230. I/O routines so they can correctly locate blocks and fragments.
  231. .PP
  232. .VS
  233. A secondary data structure called the summary information is kept on disk
  234. following the domain header.
  235. The summary information consists of a single sector and contains such
  236. information as the number of free blocks and file descriptors.
  237. The Ofs_SummaryInfo structure is defined in <kernel/fsdm.h>.
  238. The location of the summary sector is stored in the \fBDisk_Label\fR.
  239. The summary sector can be read and written using the 
  240. \fBDisk_ReadSummaryInfo\fR and \fBDisk_WriteSummaryInfo\fR procedures.
  241. .PP
  242. The detailed structure of a log structured file system is defined
  243. by a LfsSuperBlock structure whose location on disk is determined
  244. in <kernel/lfsSuperBlock.h>.  This structure can be read off of
  245. a disk using \fBDisk_ReadLfsSuperBlock\fR, and written using
  246. \fBDisk_WriteSuperBlock\fR.
  247. .PP
  248. \fBDisk_ReadLfsCheckpointHdr\fR returns the current LFS checkpoint
  249. header, which is also a front for the current checkpoint area
  250. whose bulk is hidden behind the \fBLfsCheckPointHdr\fR. If \fBareaPtr\fR
  251. is non-NULL, the area number that the header is for gets returned
  252. through the pointer.  (The area can be either zero or one, and only
  253. makes a difference if the checkpoint header is going to be written
  254. back out to disk.)
  255. \fBDisk_CheckPointTrailer\fR accesses the tail of the checkpoint
  256. area from a \fBLfsCheckPointHdr\fR returned from 
  257. \fBDisk_ReadLfsCheckPointHdr\fR. \fBDisk_WriteLfsCheckPointHdr\fR
  258. will write to disk only the \fBLfsCheckPointHdr\fR structure of the
  259. specified checkpoint area; \fBDisk_WriteLfsCheckPointArea\fR will
  260. write to disk the entire checkpoint area headed by a \fBLfsCheckPointHdr\fR,
  261. which is larger than just the structure itself (such as is returned
  262. by \fBDisk_ReadLfsCheckPointHdr\fR).
  263. \fBDisk_ForEachCheckPointRegions\fR takes a procedural argument
  264. and iterates over the \fBLfsCheckPointRegions\fR in the checkpoint area
  265. headed by a \fBLfsCheckPointHdr\fR, applying the procedural argument to
  266. every region in the checkpoint area.  If the procedure returns a
  267. non-zero value, then the iteration halts and that value is returned
  268. from \fBDisk_ForEachCheckPointRegion\fR.
  269. .SH "SECTOR I/O"
  270. .PP
  271. \fBDisk_SectorRead\fP and \fBDisk_SectorWrite\fP read and write sectors
  272. from the disk without regard to the underlying block structure.  Their
  273. \fIindex\fP argument specifies the first sector (starting from zero)
  274. to transfer, relative to the start of the partition.  The sector
  275. offsets given in the \fBDisk_Label\fP structure are useful with
  276. this routine.
  277. .SH "BLOCK I/O"
  278. .PP
  279. The file system is arranged in block-sized chunks on the disk.
  280. \fBFS_BLOCK_SIZE\fP defines how many bytes this is (currently 4 Kbytes).
  281. Due to disk geometry considerations consecutive blocks may or may not
  282. be contiguous on disk.  \fBDisk_BlockRead\fP and \fBDisk_BlockWrite\fP
  283. use geometry and block layout information in the Ofs_DomainHeader to
  284. correctly locate disk blocks.  The \fIindex\fP argument to these routines
  285. is a block index, counting from the beginning of the partition
  286. (see the warning below!).
  287. .PP
  288. \fBDisk_BadBlockRead\fP is used to re-read a bad file system block and
  289. determine which sectors are bad.  It returns a bitmask with bits
  290. set to indicate which of the sectors were successfully read.
  291. Bit \fIi\fP in the mask corresponds
  292. to sector \fIi\fP in the block.  \fBDISK_SECTORS_PER_BLOCK\fP defines
  293. how many sector there are in each file system block.
  294. .SH "FRAGMENT I/O"
  295. .PP
  296. Each file system block is sub-divided into fragments to optimize allocation
  297. of small files.  Currently the fragment size is 1 Kbyte, so there are
  298. 4 fragments to each block.
  299. \fBDisk_FragRead\fP and \fBDisk_FragWrite\fP
  300. are used to read and write fragments.
  301. The \fIindex\fP argument to these routines
  302. is a fragment index, counting from the beginning of the partition
  303. (see the warning below!).  The \fIcount\fP argument to these routines
  304. should not be greater than the number of fragments per file system block.
  305. .SH "BLOCK AND FRAGMENT INDEXES"
  306. \fBWARNING:\fP there are several caveats about block numbers and
  307. fragment numbers as used by the Sprite file system.
  308. A partition is divided into areas for bitmaps, file descriptors,
  309. and data blocks.  These divisions are specified in the Ofs_DomainHeader
  310. structure in terms of block offsets and number of blocks.
  311. However, \fIblock numbers are not kept in disk maps, only fragment numbers\fP.
  312. When traversing the direct and indirect blocks that define where
  313. a file's blocks are, fragment indexes must be converted to block
  314. indexes before using either \fBDisk_BlockRead\fP or \fBDisk_BlockWrite\fP.
  315. Also, \fIdirect block pointers in the maps are fragment indexes
  316. relative to the start of the data block area of the file system\fP.
  317. Thus to convert from a direct block pointer to a physical fragment index:
  318. .DS
  319. fragIndex = blockPointer + (headerPtr->dataOffset * FS_FRAGMENTS_PER_BLOCK);
  320. blockIndex = fragIndex / FS_FRAGMENTS_PER_BLOCK;
  321. .DE
  322. .PP
  323. The last main caveat is that \fIindirect block pointers are
  324. physical fragment indexes\fP.  They do not need to be offset in the
  325. same way as direct block pointers.  This applies to any block pointer
  326. that points to an indirect block, never to a block pointer that points
  327. to a data block.
  328. .SH "PRINTING UTILITIES"
  329. .PP
  330. The last set of procedures in this package are used to print
  331. out contents of the file system.  \fBDisk_PrintDomainHeader\fP
  332. prints out the domain header information.
  333. \fBDisk_PrintSummaryInfo\fP prints out the summary disk sector.
  334. This sector is used to keep the prefix under which the disk is
  335. exported, the current number of blocks allocated and free,
  336. and whether or not the disk was safely sync'ed at last reboot.
  337. \fBDisk_PrintFileDescBitmap\fP and \fPDisk_PrintDataBlockBitmap\fP
  338. print out the file descriptor and data block bitmaps in hex.
  339. A zero bit represents a free descriptor or block.
  340. \fBDisk_PrintDirEntry\fP prints out a directory entry.
  341. \fBDisk_PrintLfsSuperBlock\fP prints out the contents of a
  342. LFS Super Block structure.
  343. \fBDisk_PrintLfsSuperBlockHdr\fP prints out the
  344. static parameters describing the LFS layout on disk.
  345. \fBDisk_PrintLfsCheckPointHdr\fP prints out the
  346. structure describing and heading a LFS checkpoint area.
  347. \fBDisk_PrintLfsCheckPointTrailer\fP prints out the
  348. structure capping a LFS checkpoinit area.
  349. \fBDisk_PrintLfsStableMemParams\fP prints out the
  350. configuration parameters for LFS stable memory data structures.
  351. \fBDisk_PrintLfsDescMapParams\fP prints out the
  352. LFS descriptor map layout on disk.
  353. \fBDisk_PrintLfsSegUsageParams\fP prints out the
  354. LFS segment usage array layout description on disk.
  355. \fBDisk_PrintLfsFileLayoutParams\fP prints out the
  356. number of file descriptors packed together per block.
  357. .SH SEE ALSO
  358. fscheck, fsmake, labeldisk, installboot
  359. .SH KEYWORDS
  360. disk, block, sector, fragment
  361.  
  362.